package com.axend.aerosense.base.database.device;

import android.content.Context;

import androidx.annotation.NonNull;
import androidx.room.Room;
import androidx.room.migration.Migration;
import androidx.sqlite.db.SupportSQLiteDatabase;

import com.axend.aerosense.base.bean.ChooseDeviceBean;


/**
 * @description 设备数据库管理类
 * @author chenjiasheng
 * @time 2023/5/12 15:38
*/
public class DeviceInfoManager {

    public static String DB_NAME = "device.db";//数据库名称
    public static DeviceInfoDataBase deviceInfoDb;


    public static DeviceInfoDataBase getInstance(Context context) {
        if (deviceInfoDb == null) {
            deviceInfoDb = Room.databaseBuilder(context, DeviceInfoDataBase.class, DB_NAME)
                    .allowMainThreadQueries()
                    //.fallbackToDestructiveMigration()//这个方法也可以迁移数据库，但会将数据摧毁导致数据的丢失
                    .addMigrations(MIGRATION_1_2)
                    .build();
        }
        return deviceInfoDb;
    }


    /**
     * 数据库版本管理
     */
    static final Migration MIGRATION_1_2 = new Migration(1, 2) {
        @Override
        public void migrate(@NonNull SupportSQLiteDatabase database) {

        }
    };

    //查询
    public static synchronized ChooseDeviceBean.DeviceInfo getDeviceType(Context context, String type) {
        return getInstance(context).deviceInfoDao().queryDeviceType(type);
    }


}
